package cn.szq.concurrent.thread.stop;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * @ClassName: TestVolatileStop
 * @Description:
 * @Author: szq
 * @Date: 2021-09-26 18:20:45
 */
public class TestVolatileStop {

    public static void main(String[] args) throws InterruptedException {
        ArrayBlockingQueue storage = new ArrayBlockingQueue(8);

        Producter producter = new Producter(storage);
        Thread producterThread = new Thread(producter);
        producterThread.start();
        Thread.sleep(500);

        Consumer consumer = new Consumer(storage);
        while (consumer.needMoreNum()){
            System.out.println(consumer.storage.take() + "被消费了。。。");
            Thread.sleep(100);
        }

        System.out.println("消费者不需要更多数据了。");

        producter.cancled = true;
        System.out.println(producter.storage.size());
        producterThread.interrupt();

    }
}
